.PHONY: clean debug


PROJ = SyscallEva
OUT_DIR = _build
PROJ_DIR = $(abspath .)

SRC = $(wildcard $(PROJ_DIR)/src/*.c)
INCLUDE_PATH += -I$(PROJ_DIR)/src

SRC_FILES = $(notdir $(SRC))
OBJ := $(SRC_FILES:.c=.o)
OBJ := $(addprefix $(OUT_DIR)/objs/, $(OBJ))

TARGET =  $(OUT_DIR)/$(PROJ).elf

# DEFINES = ""
CFLAGS += $(INCLUDE_PATH) $(DEFINES) -g
DEPFLAGS = -MT $@ -MD -MP -MF $(OUT_DIR)/deps/$(*F).d
LDFLAGS := -pthread -g

debug:
	@echo "Compiling:" $(TARGET)
	make $(TARGET)
	@echo "Runing:" $(TARGET)
	@make --no-print-directory run

$(OUT_DIR):
	mkdir -p $(OUT_DIR)
	mkdir -p $(OUT_DIR)/objs
	mkdir -p $(OUT_DIR)/deps

$(TARGET): $(OBJ)
	$(CC) $(LDFLAGS) $^ -o $@

$(OUT_DIR)/objs/%.o: src/%.c | $(OUT_DIR)
	$(CC) $(DEPFLAGS) $(CFLAGS) -c $^ -o $@ $(LDFLAGS)

run:
	@./$(TARGET) test.txt

clean:
	rm -rf _build
